import java.util.Arrays;
import java.util.Collections;

class Solution {
    public long maximumTotalSum(int[] maximumHeight) {
        Arrays.sort(maximumHeight);
        long sum=0;
        sum+=maximumHeight[maximumHeight.length-1];
        for (int i = maximumHeight.length-2; i >= 0; i--) {
            maximumHeight[i]=Math.min(maximumHeight[i],maximumHeight[i+1]-i);
            if(maximumHeight[i]<=0){
                return -1;
            }
            sum+=maximumHeight[i];
        }
        return sum;
    }
}